package ssm.blog.service.impl;

import org.springframework.stereotype.Service;
import ssm.blog.dao.UserMapper;
import ssm.blog.entity.User;
import ssm.blog.entity.UserExample;
import ssm.blog.service.UserService;
import ssm.blog.util.MD5Util;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: lyon
 * @description: 用户-服务层
 * @author: Lyon
 * @create: 2018-05-13 22:18
 **/
@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper mapper;
    @Override
    public List<User> getUserByUsername(String username) {
        UserExample example=new UserExample();
        example.createCriteria().andUsernameEqualTo(username);
        return mapper.selectByExample(example);
    }

    @Override
    public int countByUsername(String username) {
        UserExample example=new UserExample();
        example.createCriteria().andUsernameEqualTo(username);
        return mapper.countByExample(example);
    }

    @Override
    public int addUser(User user) {
        user.setType(2);
        user.setProfile("用户");
        user.setPassword(MD5Util.md5(user.getPassword(),"lyon"));
        return mapper.insert(user);
    }
}
